**** REPLICATION OF ANALYSIS
**** Kefford, G., Moffitt, B. and Werner, A., 2023. Nativism, civic nationalism and the malleability of voter attitudes. Acta Politica, 58(2), pp.424-447.
*****
clear
use Kefford,Moffit,Werner2023ActaPolitica.dta, clear
set scheme plotplainblind
set more off


tab exp_group seen_video, mis
tab exp_group respect_laws
tab exp_group feel_Aus
tab exp_group support_wrongAus
tab exp_group immi_jobs
tab exp_group immi_incr
tab exp_group immi_culture
tab exp_group aus_identity
tab exp_group white_adv
tab exp_group aus_life
tab exp_group incr_diversity
tab exp_group migr_culture
tab exp_group prefer_white

* label experiment groups
label var exp_group experiment
label define experiment 3 "control" 1 "negative frame" 2 "positive frame"
label values exp_group experiment

* turn around variable coding
drop immi_incr
gen immi_incr = . 
replace immi_incr = 3 if b13_2 == "Strongly Disagree"
replace immi_incr = 2 if b13_2 == "Disagree" 
replace immi_incr = 1 if b13_2 == "Agree" 
replace immi_incr = 0 if b13_2 == "Strongly Agree" 
drop incr_diversity
gen incr_diversity = .
replace incr_diversity = 3 if b14_1 == "Very bad"
replace incr_diversity = 2 if b14_1 == "Bad"
replace incr_diversity = 1 if b14_1 == "Good"
replace incr_diversity = 0 if b14_1 == "Very good"
drop aus_identity
gen aus_identity = . 
replace aus_identity = 3 if b15_1 == "Strongly Disagree"
replace aus_identity = 2 if b15_1 == "Disagree" 
replace aus_identity = 1 if b15_1 == "Agree" 
replace aus_identity = 0 if b15_1 == "Strongly Agree" 
drop white_adv
gen white_adv = . 
replace white_adv = 3 if b15_2 == "Strongly Disagree"
replace white_adv = 2 if b15_2 == "Disagree" 
replace white_adv = 1 if b15_2 == "Agree" 
replace white_adv = 0 if b15_2 == "Strongly Agree" 
drop migr_culture
gen migr_culture = .
replace migr_culture = 3 if b14_2 == "Very bad"
replace migr_culture = 2 if b14_2 == "Bad"
replace migr_culture = 1 if b14_2 == "Good"
replace migr_culture = 0 if b14_2 == "Very good"


** Add other variables and helpers
replace gender = . if gender == 2
replace employ = 2 if employ == 3
label var employ employ
label define employ 0 "full-time" 1 "part-time" 2 "unemployed" 4 "retired" 5 "student" 6 "keeping house" 7 "other"
label val employ employ
label var education education
label define education 0 "<12 years" 1 "12 years" 2 "(Adv) Diploma" 3 "BA" 4 "Grad Dipl/Cert" 5 "Postgrad"
label val education education
gen urban = 1
replace urban = 0 if geo_gccsa_au_interlude == "Rest of NSW" | geo_gccsa_au_interlude == "Rest of NT" |geo_gccsa_au_interlude == "Rest of Qld" |geo_gccsa_au_interlude == "Rest of SA" |geo_gccsa_au_interlude == "Rest of Tas." |geo_gccsa_au_interlude == "Rest of Vic." | geo_gccsa_au_interlude == "Rest of WA" 
tab urban

gen vote19_four = .
replace vote19_four = 0 if vote19 == 0
replace vote19_four = 1 if vote19 == 1 | vote19 == 2 | vote19 == 4
replace vote19_four = 2 if vote19 == 5
replace vote19_four = 3 if vote19 == 6
label var vote19_four party
label define party 0 "Labor" 1 "Liberal/National" 2 "Greens" 3 "One Nation"
label val vote19_four party

gen left_party = 0 if vote19_four == 1 | vote19_four == 3
replace left_party = 1 if vote19_four == 0 | vote19_four == 2
label var left_party left
label define left 0 "right voter" 1 "left voter"
label val left_party left

gen weight = round(module_weight)
**********************************************************
*** Create nativism, civic nationalism and populism scores
**********************************************************


* NATIVISM score following table 2
egen nativism = rowtotal(incr_diversity migr_culture prefer_white immi_culture immi_jobs immi_incr white_adv)
replace nativism = nativism / 7

* CIVIC NATIONALISM score following table 2
egen civicnat = rowtotal(respect_laws feel_Aus support_wrongAus aus_identity aus_life)
replace civicnat = civicnat / 5

* POPULISM score as developed in paper 1
gen pop_all = (people_decide + rep_ordinary + elected_corrup + bad_decisions + parties_care + media_mates + bad_views + disagree_inform + pol_entertain + offend + pol_ordinary)/11
tab pop_all
sum pop_all
* Use mean as cutoff point
gen populists = 0 if pop_all <=1.710547
replace populists = 1 if pop_all >1.710547
tab populists

*******************
** Descriptives: DVs and moderator
******************* 

label var civicnat "Civic Nationalism"
label var nativism Nativism

outreg2 using "Table 3 - Summary statistics - Australia - Outreg.doc", ///
	replace sum(log) keep(nativism civic) 

graph box nativism civic , legend(order(1 "Nativism" 2 "Civic Nationalism") position(6) row(1))
graph export "Boxplot_NativismCivic.tif", as(tif) replace	

vioplot nativism civic 
graph export "Violin_NativismCivic.tif", as(tif) replace

*********************
** seen video 
*********************

tab seen_video exp_group, col

*********************
** DVs by Frame 
*********************

graph box nativism civic, over(exp_group) legend(order(1 "Nativism" 2 "Civic Nationalism") position(6) row(1))
graph export "Boxplot_Experiment_NativismCivic.tif", as(tif) replace	

graph box nativism , over(exp_group) title(Nativism) ytitle("")
graph save n, replace

graph box  civic, over(exp_group) title(Civic Nationalism) ytitle("")
graph save c, replace

graph combine n.gph c.gph
graph export "Boxplot_Experiment_NativismCivic_2.tif", as(tif) replace	

* Nativism

bysort exp_group: sum nativism [aweight= module_weight]
anova nativism b3.exp_group [aweight= module_weight]
regress
anova nativism b1.exp_group [aweight= module_weight]
regress

* Civic nationalism
bysort exp_group: sum civic [aweight= module_weight]
anova civic b3.exp_group [aweight= module_weight]
regress
anova civic b1.exp_group [aweight= module_weight]
regress


***********************
** DVs by frame and mainstream vs rrp
***********************

gen party_type = .
replace party_type = 0 if vote19_four == 1 | vote19_four == 2 | vote19_four == 0
replace party_type = 1 if vote19_four == 3 
label var party_type party_type
label define party_type 0 "Mainstream Voter" 1 "RRP Voter"
label val party_type party_type

********* NATIVISM **********

reg nativism b3.exp_group##i.party_type gender age income i.education urban
outreg2 using Treatment_partytype.doc, eform replace ctitle(Nativism) dec(2) label(proper) side noparen alpha(0.001, 0.01, 0.05)

margins, dydx(exp_group) at(party_type=(0))
marginsplot, recast(scatter) title(Mainstream Voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save  type1
margins, dydx(exp_group) at(party_type=(1))
marginsplot, recast(scatter) title(RRP Voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  type2

graph combine type1.gph type2.gph, ycommon
graph export "Treatment effect_Nativism_mainstreamRRPvoters.tif", as(tif) replace

********* Civic Nationalism **********

reg civic b3.exp_group##i.party_type gender age income i.education urban
outreg2 using Treatment_partytype.doc, eform append ctitle(Civic Nationalism) dec(2) label(proper) side noparen alpha(0.001, 0.01, 0.05)

margins, dydx(exp_group) over(party_type)
marginsplot, recast(scatter) title(Effect on Civic Nationalism) legend(order(1 "Hanson video" 2 "SBS video") position(6) row(1)) xtitle("") xlabel(0 "right-wing voters" 1 "left-wing voters") ytitle(Marginal effect on linear prediction) yline(0)

margins, dydx(exp_group) at(party_type=(0))
marginsplot, recast(scatter) title(Mainstream Voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save  type3
margins, dydx(exp_group) at(party_type=(1))
marginsplot, recast(scatter) title(RRP Voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  type4

graph combine type3.gph type4.gph, ycommon
graph export "Treatment effect_CivicNationalism_mainstreamRRPvoters.tif", as(tif) replace


***********************
** DVs by frame and voter groups 
***********************

********* NATIVISM **********

reg nativism b3.exp_group##i.vote19_five gender age income i.education urban
outreg2 using Treatment_voters.doc, eform replace ctitle(Nativism) dec(2) label(proper) side noparen alpha(0.001, 0.01, 0.05)

margins, dydx(exp_group) at(vote19_five=(0))
marginsplot, recast(scatter) title(Labor voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save lab1 , replace
margins, dydx(exp_group) at(vote19_five=(1))
marginsplot, recast(scatter) title(Liberal/National voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  lib1 , replace
margins, dydx(exp_group) at(vote19_five=(2))
marginsplot, recast(scatter) title(Green voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save green1, replace  
margins, dydx(exp_group) at(vote19_five=(3))
marginsplot, recast(scatter) title(One Nation voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  on1 , replace
margins, dydx(exp_group) at(vote19_five=(4))
marginsplot, recast(scatter) title(Independent voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  ind , replace

graph combine lab1.gph lib1.gph green1.gph on1.gph ind.gph, ycommon
graph export "Treatment effect_Nativism_voters.tif", as(tif) replace

graph combine lab1.gph lib1.gph green1.gph on1.gph, ycommon
graph export "Treatment effect_Nativism_voters_2.tif", as(tif) replace

********* Civic Nationalism **********

reg civic b3.exp_group##i.vote19_five gender age income i.education urban
outreg2 using Treatment_voters.doc, eform append ctitle(Civic Nationalism) dec(2) label(proper) side noparen  alpha(0.001, 0.01, 0.05)

margins, dydx(exp_group) at(vote19_five=(0))
marginsplot, recast(scatter) title(Labor voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save lab2, replace
margins, dydx(exp_group) at(vote19_five=(1))
marginsplot, recast(scatter) title(Liberal/National voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  lib2, replace
margins, dydx(exp_group) at(vote19_five=(2))
marginsplot, recast(scatter) title(Green voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle(Marginal effect on linear prediction) yline(0)
graph save green2, replace
margins, dydx(exp_group) at(vote19_five=(3))
marginsplot, recast(scatter) title(One Nation voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  on2, replace
margins, dydx(exp_group) at(vote19_five=(4))
marginsplot, recast(scatter) title(Independent voters) xtitle("") xlabel(1 `""Negative" "Frame" "'  2 `""Positive" "Frame""') ytitle("") yline(0)
graph save  ind2, replace


graph combine lab2.gph lib2.gph green2.gph on2.gph ind2.gph , ycommon
graph export "Treatment effect_CivicNationalis_voters.tif", as(tif) replace

graph combine lab2.gph lib2.gph green2.gph on2.gph , ycommon
graph export "Treatment effect_CivicNationalis_voters_2.tif", as(tif) replace

************************
* Nativism, right wing voters for whom the SBS video is new

reg nativism b1.exp_group##i.seen_video gender age income i.education urban if left_party == 0
outreg2 using Treatment_seen.doc, eform replace ctitle(Nativism * Rightwing voters) dec(2) label(proper) side noparen 

margins, dydx(exp_group) over(seen_video)
marginsplot, recast(scatter) title("Effect on Nationalism, among right-wing voters") legend(order(1 "Hanson video" 2 "SBS video") position(6) row(1)) xtitle("") xlabel(0 "not seen video" 1 "seen video") ytitle(Marginal effect on linear prediction) yline(0)

*******************
** TREATMENT EFFECT with ra subcommand because treatment is not estimated by contrls
********************

gen treatment = exp_group
replace treatment = 0 if exp_group == 3
label var treatment  treatment
label define treatment 0 "control" 1 "Hanson video" 2 "SBS video"
label values treatment treatment

* Treatment only

teffects ra (nativism vote19 gender age income i.education urban) (treatment)
teffects ra (civic vote19 gender age income i.education urban) (treatment)	

teffects ra (nativism vote19 gender age income i.education urban) (treatment), atet
teffects ra (civic vote19 gender age income i.education urban) (treatment), atet

* Treatment by mainstream vs RRP

by party_type, sort: teffects ra (nativism gender age income i.education urban) (treatment)	, atet
by party_type, sort: teffects ra (civic gender age income i.education urban) (treatment)	, atet

* Treatment by vote choice

by vote19_four, sort: teffects ra (nativism gender age income i.education urban) (treatment)	, atet
by vote19_four, sort: teffects ra (civic gender age income i.education urban) (treatment)	, atet

gen vote19_five = vote19_four
replace vote19_five = 4 if vote19 == 7

by vote19_five, sort: teffects ra (nativism gender age income i.education urban) (treatment)	, atet
by vote19_five, sort: teffects ra (civic gender age income i.education urban) (treatment)	, atet

* Treatment by left and right voters

by left_party, sort: teffects ra (nativism gender age income i.education urban) (treatment)	, atet
by left_party, sort: teffects ra (civic gender age income i.education urban) (treatment)	, atet

*******************
** Appendix -- individual items
********************

*****
* Check that these are two individual scores
*****

factor incr_diversity migr_culture prefer_white immi_culture immi_jobs immi_incr white_adv respect_laws feel_Aus support_wrongAus aus_identity aus_life [fweight=weight] , ipf 
rotate, promax blanks(0.40) 
estat common

factor incr_diversity migr_culture prefer_white immi_culture immi_jobs immi_incr white_adv respect_laws feel_Aus support_wrongAus aus_identity aus_life [fweight=weight] , ipf fac(2)
rotate, promax blanks(0.40) 
estat common

**** experimental groups vs control
foreach var of varlist respect_laws feel_Aus support_wrongAus immi_jobs immi_incr immi_culture aus_identity white_adv aus_life incr_diversity migr_culture prefer_white {
	anova `var' treatment [aweight= module_weight]
	regress
}


**** ATTs

foreach var of varlist respect_laws feel_Aus support_wrongAus aus_identity aus_life  immi_jobs immi_incr immi_culture incr_diversity white_adv  migr_culture prefer_white {
	teffects ra (`var'  gender age income i.education urban) (treatment)	, atet
}


*** Robustness check with Civic only the two high loading items respect_laws feel_Aus 

egen civic_rob = rowtotal(respect_laws feel_Aus)
replace civic_rob = civic_rob/2

pwcorr  civic_rob civicnat, sig
regress

teffects ra (civic_rob vote19 gender age income i.education urban) (treatment), atet
by party_type, sort: teffects ra (civic_rob gender age income i.education urban) (treatment)	, atet

clear
exit
